package com.lehecai.core.search.api;

import net.sf.json.JSON;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

/**
 * @author hanwenda
 * filter实体
 */
public class SearchApiRequestFilterItem {

    /**
     * 比较类型
     */
	private String type;

    /**
     * 字段
     */
	private String field;

    /**
     * 值
     */
	private Object value;

    public SearchApiRequestFilterItem(String type, String field, Object value) {
        this.type = type;
        this.field = field;
        this.value = value;
    }

    public String getType() {
        return type;
    }

    public String getField() {
        return field;
    }

    public Object getValue() {
        return value;
    }

    public void setType(String type) {
        this.type = type;
    }

    public void setField(String field) {
        this.field = field;
    }

    public void setValue(Object value) {
        this.value = value;
    }

    public JSON toJSON() {
        // JSONObject
        JSONObject jsonObject = new JSONObject();
        jsonObject.put(SearchApiConstant.API_PARAMETER_FILTER_TYPE, this.type);

        JSONArray fieldArray = new JSONArray();
        fieldArray.add(this.field);
        jsonObject.put(SearchApiConstant.API_PARAMETER_FILTER_FIELD, fieldArray);

        JSONArray valueArray = new JSONArray();
        valueArray.add(this.value);
        jsonObject.put(SearchApiConstant.API_PARAMETER_FILTER_VALUE, valueArray);

        return jsonObject;
    }
}
